#include "../core/engine/interface.h"
#include "picture.h"

namespace sleek
{
    namespace gui
    {
        picture::picture(core::engine::interface *m) : frame(m), pic(0)
        {
            isHovored = false;
        }
        picture::~picture()
        {
        }
        void picture::setTexture(texture::texture *i)
        {
            pic = i;
            if(pic) box.setSizeFromUpperLeft(core::math::vector2di(i->getOriginalSize().width,i->getOriginalSize().height));
        }
        bool picture::manage(core::device::input *e)
        {
            if(frame::manage(e)) { return false; }
            bool last = isHovored;

            bool current = box.intersect(e->mouse_pos);
            if(last != current)
            {
                isHovored = current;

                e->gui.called = this;
                if(current) { e->gui.code = gui::IET_PICTURE_HOVORED; return true; }
                else { e->gui.code = gui::IET_PICTURE_FOCUSED; return true; }
            }
            return false;
        }
        texture::texture* picture::getTexture()
        {
            return pic;
        }
        void picture::render()
        {
            if(!pic) return;
            mom->getDrawManager()->setActiveMaterial(&rnd);
            mom->getDrawManager()->drawTexture(pic,box.getUpperLeft());
        }
    }
}
